package com.link.play.fit.ai.ui.main.saveFood.details.modifyPage

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.link.play.fit.ai.R
import com.link.play.fit.ai.base.BaseActivity
import com.link.play.fit.ai.bean.CalendarStatusData
import com.link.play.fit.ai.databinding.ModifyProteinLayoutBinding

class ModifyProteinAc : BaseActivity<ModifyProteinLayoutBinding>(ModifyProteinLayoutBinding::inflate)   {
    private var mValue = ""
    private var calendarStatusData: CalendarStatusData?=null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initListener()
        initData()
    }

    private fun initListener(){
        with(binding){
            backImage.setOnClickListener {
                finish()
            }
            doneText.setOnClickListener {
                val intent = Intent().apply {
                    putExtra("result_key", binding.editCalValue.text.toString())
                }
                setResult(Activity.RESULT_OK, intent)
                finish()
            }
            revertText.setOnClickListener {
                binding.editCalValue.setText(mValue)
            }
        }
    }

    private fun initData(){
        mValue = intent.getStringExtra("value").toString()
        calendarStatusData = intent.getSerializableExtra("bean") as CalendarStatusData?
        binding.caloriesValueText.text = mValue


        binding.editCalValue.setText(mValue)
        calendarStatusData?.let {
            binding.proteinProgress.max = it.proteinDaily
            binding.proteinProgress.progress = it.consumeProteinDaily
            if (it.proteinDaily > it.consumeProteinDaily) {
                binding.outleftText.text =
                    getString(R.string.out_of_left, "${it.proteinDaily - it.consumeProteinDaily}")
            } else {
                binding.outleftText.text =
                    getString(R.string.out_of_over, "${it.consumeProteinDaily - it.proteinDaily}")
            }
        }
    }

}